package com.yingside.collection.book;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TestManager {
    public static void main(String[] args) {
        Book b1 = new Book(1,"斗破苍穹","天蚕土豆",30);
        Book b2 = new Book(2,"星辰变","番茄",10);
        Book b3 = new Book(3,"诡秘之主","乌贼",20);
        Book b4 = new Book(4,"斗罗大陆","三少",70);
        Book b5 = new Book(5,"肾虚","辰东",80);

//        List<Book> books = new ArrayList<>();
//        books.add(b1);
//        books.add(b2);
//        books.add(b3);
//        books.add(b4);
//        books.add(b5);

//        List<Book> books2 = new ArrayList<>();
//
//        for (int i = 0; i < books.size(); i++) {
//            if(books.get(i).getPrice() <= 20){
//                books2.add(books.get(i));
//            }
//        }
//
//        //要求返回的是一个数组
//        Book [] bs = books2.toArray(new Book[books2.size()]);

        BookManager bm = new BookManager();
        bm.add(b1);
        bm.add(b2);
        bm.add(b3);
        bm.add(b4);
        bm.add(b5);

        Book[] bs = bm.filter(new BookFilter() {
            public boolean filter(int id, String bookname, String author, double price) {
                return bookname.indexOf("斗") == -1 ? false : true;
            }
        });

        System.out.println("Arrays.toString(bs) = " + Arrays.toString(bs));


    }
}
